import Data_Save
import Machine_Learning
import BaseFunction
import pylab as plt
import pandas as pd

BaseFunction.Correct_Show()

data = Data_Save.Load_Save_Data('fiexd_data.pkl')
X = data.iloc[:, :-1]
Y = data.iloc[:, -1]

# 评价脚本

# # 读取训练的模型
# knn_model=Data_Save.Load_Save_Data(filename='KNN_model.pkl')
# # 读取最好的模型
best_knn = Data_Save.Load_Save_Data(filename='best_knn.pkl')
best_logisitc = Data_Save.Load_Save_Data(filename='best_logistic.pkl')
best_DT = Data_Save.Load_Save_Data(filename='best_DT.pkl')
best_bestmodel = Data_Save.Load_Save_Data(filename='bestmodel_Ensemble.pkl')

# KNN
# 初始化评价类
E1 = Machine_Learning.Evaluate(best_knn, X, Y)
E2 = Machine_Learning.Evaluate(best_logisitc, X, Y)
E3 = Machine_Learning.Evaluate(best_DT, X, Y)
E4 = Machine_Learning.Evaluate(best_bestmodel, X, Y)

# 获取正确率
acc1 = E1.Get_accury()
acc2 = E2.Get_accury()
acc3 = E3.Get_accury()
acc4 = E4.Get_accury()
E1.Print_report()
E2.Print_report()
E3.Print_report()
E4.Print_report()
E1.Draw_confusion_matrix()
E2.Draw_confusion_matrix()
E3.Draw_confusion_matrix()
E4.Draw_confusion_matrix()

r = pd.DataFrame([acc1, acc2, acc3, acc4], index=['优化后KNN', '优化后logistic', '优化后决策树', '优化后集成学习'])
plt.show()
Data_Save.SavetoExcel([r],['分类正确率'],'预测分类正确率.xlsx')